<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form
        :model="where"
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="reload"
        @submit.native.prevent>
        <el-row :gutter="15">
          <el-col :lg="11" :md="12">
            <el-form-item label="统计年度:">
              <el-col :lg="8" :md="12">
                <el-date-picker
                  type="year"
                  class="ele-fluid"
                  v-model="where.startYear"
                  value-format="yyyy"
                  format="yyyy"
                  placeholder="请选择开始年"/>
              </el-col>
              <el-col :lg="2" :md="12">
                至
              </el-col>
              <el-col :lg="8" :md="12">
                <el-date-picker
                  type="year"
                  class="ele-fluid"
                  v-model="where.endYear"
                  value-format="yyyy"
                  format="yyyy"
                  placeholder="请选择结束年"/>
              </el-col>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="项目类别:">
              <el-select
                filterable
                clearable
                v-model="where.project"
                @change="$forceUpdate()"
                size="small"
                placeholder="-请选择项目类别-"
                class="ele-block">
                <el-option v-for="item in projectList" :key="item.id" :label="item.name" :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row :gutter="15">
          <el-col :lg="6" :md="12">
            <el-form-item label="年级:">
              <el-select
                filterable
                clearable
                v-model="where.grade"
                @change="$forceUpdate()"
                size="small"
                placeholder="-请选择年级-"
                class="ele-block">
                <el-option v-for="item in gradeList" :key="item.id" :label="item.name" :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="6" :md="12">
            <el-form-item label="所属院系:">
              <el-select
                filterable
                clearable
                v-model="where.department"
                @change="$forceUpdate()"
                size="small"
                placeholder="-请选择所属院系-"
                class="ele-block">
                <el-option v-for="item in departmentsList" :key="item.id" :label="item.name" :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="10" :md="12">
            <el-form-item label="统计日期:">
              <el-col :lg="8" :md="12">
                <el-date-picker
                  type="date"
                  class="ele-fluid"
                  v-model="where.startTime"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  placeholder="请选择开始日期"/>
              </el-col>
              <el-col :lg="2" :md="12">
                至
              </el-col>
              <el-col :lg="8" :md="12">
                <el-date-picker
                  type="date"
                  class="ele-fluid"
                  v-model="where.endTime"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  placeholder="请选择结束日期"/>
              </el-col>
            </el-form-item>
          </el-col>

          <el-col :lg="6" :md="12">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                @click="reload">查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>

      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        :selection.sync="selection"
        height="calc(100vh - 315px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar">
<!--          <el-button-->
<!--            size="small"-->
<!--            type="success"-->
<!--            icon="el-icon-download"-->
<!--            class="ele-btn-icon"-->
<!--            @click="exportExcel">导出-->
<!--          </el-button>-->
        </template>

        <!-- 操作列 -->
        <template slot="action" slot-scope="{row}">
          <el-link
            type="primary"
            :underline="false"
            @click="openAnalysis(row)"
            >院系画像
          </el-link>
          <el-link
            type="primary"
            :underline="false"
            @click="openagailan(row)"
          >专业概览
          </el-link>
        </template>
      </ele-pro-table>
    </el-card>
  </div>
</template>

<script>
import {mapGetters} from "vuex";

export default {
  name: "index",
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格搜索条件
      where: {},
      url: '/classPortrait/index',
      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'grade_name',
          label: '年级',
          width: 60,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'project_name',
          label: '项目',
          minWidth: 200,
          align: 'center',
        },
        {
          prop: 'department_name',
          label: '院系',
          minWidth: 200,
          align: 'center',
        },
        {
          prop: 'avg',
          label: '平均分',
          width: 200,
          align: 'center',
        },
        {
          prop: 'super',
          label: '优秀人数',
          width: 200,
          align: 'center',
        },
        {
          prop: 'good',
          label: '良好人数',
          align: 'center',
          width: 100,
        },
        {
          prop: 'fail',
          label: '不及格人数',
          width: 200,
          align: 'center',
        },
        {
          prop: 'goodRate',
          label: '优良率',
          width: 200,
          align: 'center',
        },
        {
          prop: 'passRate',
          label: '合格率',
          width: 200,
          align: 'center',
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 150,
          align: 'center',
          resizable: false,
          slot: 'action',
          fixed: "right"
        }
      ],
      // 表格选中数据
      selection: [],
      projectList: [],
      gradeList: [],
      departmentsList: [],
    }
  },
  mounted() {
    this.getGradeList()
  },
  methods: {
    openAnalysis(row){
      this.$router.push({path: '/evaluate/yuanxiAnalysis', query: {name: row.department_name,id:row.id}});
    },
    openagailan(row){
      this.$router.push({path: '/professpj', query: {name: row.department_name,id:row.id}});
    },
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.reload();
    },
    /* 显示编辑 */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },
    getGradeList() {
      this.$http.get("/project/index?limit=99999").then(response => {
        if (response.data.code === 0) {
          this.projectList = response.data.data

        }else {
          this.$message.error(response.data.msg);
        }
      })

      this.$http.get("/grade/index?limit=99999").then(response => {
        if (response.data.code === 0) {
          this.gradeList = response.data.data

        } else {
          this.$message.error(response.data.msg);
        }
      })

      this.$http.get('/departments/index?limit=99999').then(res => {
        if (res.data.code === 0) {
          this.departmentsList = res.data.data;

        } else {
          this.$message.error(res.data.msg);
        }
      })

    },
    /* 导出数据Excel */
    exportExcel() {
      let info = JSON.parse(JSON.stringify(this.where));
      this.$http
        .get("/departments/exportExcel", info)
        .then((res) => {
          let data = res.data;
          if (data.code == 0) {
            // 下载文件
            window.location.href = data.data;
            this.$message({
              type: "success",
              message: "导出成功",
            });
          } else {
            this.$message.error("导出失败");
          }
        })
    },
  }
}
</script>

<style scoped>

</style>
